//
//  TouchEffect.cpp
//  petgame
//
//  Created by zz on 2018/12/15.
//

#include "TouchEffect.hpp"


TouchEffect*TouchEffect::create(int type,Vec2 pos){
    
//    创建对象
    auto toucheffect=new TouchEffect();
//    初始化
    if(toucheffect&&toucheffect->init(type,pos)){
//        自动释放
        toucheffect->autorelease();
        return toucheffect;
    }else{
    
        CC_SAFE_DELETE(toucheffect);
        return NULL;
    }
}
bool TouchEffect::init(int type,Vec2 pos){
    
//    父类初始化
    if(!Node::init()){
        
        return false;
    }
    
    switch (type) {
        case 0:{
//            创建星星
            this->p1=Sprite::create("k3.png");
            this->p1->setScale(0.2);
            this->p1->setPosition(pos+Vec2(0,20));
            this->addChild(this->p1);
//            创建动画
            auto ac1=MoveBy::create(0.6,Point(0,60));
//            创建回调
            auto callfun=CallFunc::create(CC_CALLBACK_0(TouchEffect::destory,this));
            auto seq=Sequence::create(EaseIn::create(ac1,0.1),callfun,NULL);
            this->p1->runAction(seq);
        }
            break;
        case 1:{
            
        }
            break;
        case 2:{
            
        }
            break;
        default:
            break;
    }
    return true;
}


void TouchEffect::destory(){
//    c移除自身
    this->removeFromParent();
}
